import {BasicColumn, FormSchema} from '/@/components/Table';
import {render} from '/@/utils/common/renderUtils';

//列表数据
export const columns: BasicColumn[] = [
  {
    title: '文章分类',
    align: "center",
    dataIndex: 'cataId',
    customRender:({text}) => {
       return render.renderCategoryTree(text,'');
   },
  },
  {
    title: '文章标题',
    align: "center",
    dataIndex: 'title'
  },
  {
    title: '文章摘要',
    align: "center",
    dataIndex: 'keywords',
    customRender:({text}) =>{
      return !text ? "-" : text;
    },
  },
  // {
  //   title: '浏览量',
  //   align: "center",
  //   dataIndex: 'viewCount'
  // },
  {
    title: '状态',
    align: "center",
    dataIndex: 'status',
    filters: [
      { text: '未发布', value: '0' },
      { text: '已发布', value: '1' },
      { text: '已撤销', value: '2' },
    ],
    filterMultiple: false,
    slots: { customRender: 'statusSlot' },
  },
  {
    title: '创建时间',
    align: "center",
    sorter: true,
    dataIndex: 'createTime'
  },
  {
    title: '发布时间',
    align: "center",
    sorter: true,
    dataIndex: 'releaseTime'
  },
];

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "分类id",
    field: 'cataId',
    component: 'JCategorySelect',
    componentProps:{
      pcode: "",//back和事件未添加，暂时有问题
    },
    colProps: {span: 6},
  },
  {
    label: "文章标题",
    field: 'title',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: "创建时间",
    field: "createTime",
    component: 'RangePicker',
    componentProps: {
      showTime: true,
    },
    colProps: {span: 6},
  },
  {
    label: "状态,1：上线  0: 删除  2：下线 ",
    field: 'status',
    component: 'JSwitch',
    componentProps:{
    },
    colProps: {span: 6},
  },
];

//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '分类id',
    field: 'cataId',
    component: 'JCategorySelect',
    componentProps:{
      pcode: "", //TODO back和事件未添加，暂时有问题
    },
    dynamicRules: ({model,schema}) => {
      return [
              { required: true, message: '请输入分类id!'},
             ];
    },
  },
  {
    label: '文章标题',
    field: 'title',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
              { required: true, message: '请输入文章标题!'},
             ];
    },
  },
  {
    label: '摘要',
    field: 'keywords',
    component: 'InputTextArea',
  },
  {
    label: '内容',
    field: 'content',
    component: 'JEditor',
    dynamicRules: ({model,schema}) => {
      return [
              { required: true, message: '请输入内容!'},
             ];
    },
  },
  {
    label: '状态,1：上线  0: 删除  2：下线 ',
    field: 'status',
    component: 'JSwitch',
    componentProps:{
    },
    dynamicRules: ({model,schema}) => {
      return [
              { required: true, message: '请输入状态,1：上线  0: 删除  2：下线 !'},
             ];
    },
  },
  {
    label: '咨询图片',
    field: 'icon',
    component: 'JImageUpload',
    componentProps:{
    },
  },
	// TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
